home *** CD-ROM | disk | FTP | other *** search
/ The Web Masters 11 / WEB_11.iso / 100domes / Antechinus JavaScript Editor 2.0 / Setup.exe / Setups / JSEd / Installed / Solutions / Animation / cplib.js < prev    next >
Text File  |  2002-04-16  |  3KB  |  114 lines

  1. // C Point JavaScript Library v3.6
  2. // Copyright⌐ 1999-2002 C Point Pty Ltd, 71 Williamson Road, Para Hills 5096
  3. // Web: http://www.c-point.com Email: c-point@c-point.com
  4.  
  5. // *************************************************************** //
  6. // To use the C Point JavaScript Library you must be a registered 
  7. // user of Antechinus JavaScript Editor.
  8. // *************************************************************** //
  9.  
  10. // ************  Move object functions ************ 
  11. function initClassdraggable()
  12. {
  13.     bMoving = false;
  14.     document.onmousedown=startMove;
  15.     document.onmousemove=moveObj;
  16.     document.onmouseup=new Function("bMoving=false");
  17. }
  18.  
  19. function moveObj()
  20. {
  21.     if(!bMoving) return true;
  22.     if(event.button!=1) return true;
  23.  
  24. // Reposition the object, keeping the same distance from the cursor
  25.     ob.style.pixelLeft=event.clientX-xdif;
  26.     ob.style.pixelTop=event.clientY-ydif;
  27.     return false;
  28. }
  29.  
  30. function startMove()
  31. {
  32. // Only "draggable" objects can move
  33.     if(event.srcElement.className!="draggable") return;
  34.  
  35.     bMoving=true;
  36. // Store the object and the differnce between the obj pos and cursor pos: it must remain the same
  37.     ob=event.srcElement;
  38.     xdif=event.clientX-event.srcElement.style.pixelLeft;
  39.     ydif=event.clientY-event.srcElement.style.pixelTop;
  40. }
  41.  
  42.  
  43. // ************ Button Functions ************ 
  44.  
  45. // 2-state button (checkbox): function toggles the 2 states
  46. function cpClickState(obj)
  47. {
  48.     if(obj.cpType=="2")
  49.     {
  50.         obj.cpType="1";
  51.         obj.src=obj.cpDn;            
  52.     }
  53.     else
  54.     {
  55.         obj.cpType="2";    
  56.         obj.src=obj.cpUp;
  57.     }
  58. }
  59.  
  60. function cpMouseOver(obj, f)
  61. {
  62.     obj.src=f;
  63. }
  64.  
  65. function cpMouseOut(obj, f)
  66. {
  67.     obj.src=f;    
  68. }
  69.  
  70. // Move/display the object at the specified location
  71. function cpPopup(ob2, x, y)
  72. {
  73.     ob2.style.posLeft=x;
  74.     ob2.style.posTop=y;
  75.     ob2.style.visibility="visible";    
  76. }
  77.  
  78. // Roll the first object, display the second at the specified location
  79. function cpMousePopOver(ob1, f, ob2, x, y)
  80. {
  81.     cpMouseOver(ob1, f);
  82.     cpPopup(ob2, x, y);    
  83. }
  84.  
  85. // Roll the first object, display the second
  86. function cpRollPopOver(ob1, f, ob2)
  87. {
  88.     cpMouseOver(ob1, f);
  89.     ob2.style.visibility="visible";
  90. }
  91.  
  92. // Restore the first object, hide the second
  93. function cpMousePopOut(ob1, f, ob2)
  94. {
  95.     cpMouseOut(ob1, f);
  96.     ob2.style.visibility="hidden";        
  97. }
  98.  
  99. // Toggle the object's visibility
  100. function cpPop(ob)
  101. {
  102.     if(ob.style.visibility=="visible") ob.style.visibility="hidden";    
  103.     else ob.style.visibility="visible";    
  104. }
  105.  
  106. // ************  Misc functions ************ 
  107.  
  108. // Return the random number between min and max
  109. function cpRandom(min, max)
  110. {
  111.     var nRand = Math.random()*(max-min+1);
  112.     return(Math.round(nRand + 0.5)+min-1);
  113. }
  114.